//
// Created by dave on 18-7-29.
//

#pragma once

#include <string>
#include "../msg_body.h"
#include "../data_utils.h"

class term_register : public msg_body {
public:
    void decode(std::vector<unsigned char> data, std::size_t start, std::size_t stop) override {
        province = read_word(data, start);
        city = read_word(data, start + 2);
        maker = std::string((char *) (&data.data()[start + 4]), 5);
        model = std::string((char *) (&data.data()[start + 9]), 8);
        device_id = std::string((char *) (&data.data()[start + 17]), 7);
        color = data[start + 24];
        license = gbk2utf8(std::string((char *) (&data.data()[start + 25]), (stop - start - 25)));
    }

    short get_province() { return province; }
    void set_province(short province) { this->province = province; }
    short get_city() { return city; }
    void set_city(short city) { this->city = city; }
    std::string get_maker() { return maker; }
    void set_maker(std::string maker) { this->maker = maker; }
    std::string get_model() { return model; }
    void set_model(std::string model) { this->model = model; }
    std::string get_device_id() { return device_id; }
    void set_device_id(std::string device_id) { this->device_id = device_id; }
    char get_color() { return color; }
    void set_color(char color) { this->color = color; }
    std::string get_license() { return license; }
    void set_license(std::string license) { this->license = license; }

private:
    /// 省域 ID（参考  GB/T 2260 中规定的行政区划代码六位中前两位）
    short province;
    /// 市县域 ID（参考  GB/T 2260 中规定的行政区划代码六位中后四位）
    short city;
    /// 制造商 ID
    std::string maker;
    /// 终端型号
    std::string model;
    /// 终端 ID
    std::string device_id;
    /// 车牌颜色（参考 JT/T415-2006 的 5.4.12） 0-未上牌, 1-蓝色, 2-黄色, 3-黑色, 4-白色
    char color;
    /// 车牌
    std::string license;
};